package ysu.sxm.ptjc.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ysu.sxm.ptjc.Dao.UserMapper;
import ysu.sxm.ptjc.Service.UserService;
import ysu.sxm.ptjc.pojo.UserInfo;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserInfo> implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public int findOperatorByString(Integer userId, String password){
        QueryWrapper<UserInfo> wrapper = new QueryWrapper<UserInfo>();
        //根据用户名查询用户对象
        int result=0;
        wrapper.eq("user_id",userId);
        UserInfo queryUser = this.getOne(wrapper);
        if (queryUser != null) {
            //用户名存在则验证密码，密码一致则登陆成功
            if (password.equals(queryUser.getPassword())) {
                result=1;
            }
        }
        return result;
    }
//    public void addUser(UserInfo userInfo){
//        userMapper.insert(userInfo);
//
//    }

//    @Override
//    public void subByIds(List<Integer> ids) {
//        userMapper.deleteBatchIds(ids);
//    }

    @Override
    public List<UserInfo> showUserByPower(String power) {
        List<String>powers=new ArrayList<String>();
        List<UserInfo>users=null;
        if (power.equals("管理员")){
            powers.add("员工");
            powers.add("组长");

        }
        else if(power.equals("老板")){
            powers.add("员工");
            powers.add("组长");
            powers.add("管理员");

        }
        users=userMapper.selectByPower(powers);
        return users;
    }

    @Override
    public UserInfo getUserByLogin(String userId, String password) {
        return userMapper.login(userId,password);
    }


    @Override
    public boolean test() {
        return false;
    }
}
